#include "scl_reader.h"
scl_reader::scl_reader()
{}
bool scl_reader::read(QIODevice *device)
{
    pcNum=0;
    apNum=0;
    gvNum=0;
    piNum=0;
    acNum=0;
    daNum=0;
    coNum=0;
    fcNum=0;
    lnNum=0;
    doNum=0;
    ldNum=0;
    ddoNum=0;
    PSUB.clear();
    PCOM.clear();
    PIED.clear();
    clear();
    setDevice(device);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "SCL")
            {
                read_data();
            }
        }
    }
    connectData();
    return !error();
}
void scl_reader::read_data()
{
    while(!atEnd())
    {
         readNext();
         if(isStartElement())
         {
             if(name() == "Communication")
             {
                 read_Communication();
             }
             if(name() == "IED")
             {
                 read_IED();
                 piNum++;
                 acNum=0;
             }
         }
         if(isEndElement())
         {
             if(name() == "SCL")
                 break;
         }
    }
}
void scl_reader::read_Communication()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "SubNetwork")
            {
                read_SubNetwork();
                pcNum++;
                apNum=0;
            }
        }
        if(isEndElement())
        {
            if(name() == "Communication")
                break;
        }
    }
}
void scl_reader::read_SubNetwork()
{
    tempPCOM.type="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("type"))
    {
        tempPCOM.type=attr1.value("type").toString();
    }
    PCOM.append(tempPCOM);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "ConnectedAP")
            {
                read_ConnectedAP();
                apNum++;
                gvNum=0;
            }
        }
        if(isEndElement())
        {
            if(name() == "SubNetwork")
                break;
        }
    }

}
void scl_reader::read_ConnectedAP()
{
    tempConnAP.apName="";
    tempConnAP.iedName="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("apName"))
    {
        tempConnAP.apName=attr1.value("apName").toString();
     //   PCOM[pcNum].connap[apNum].apName=attr1.value("apName").toString();
    }
    if(attr1.hasAttribute("iedName"))
    {
        tempConnAP.iedName=attr1.value("iedName").toString();
    }

    PCOM[pcNum].connap.append(tempConnAP);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            QXmlStreamAttributes attr;
            /*
            if(name() == "GSE")
            {
                tempgv.cbname="";
                tempgv.ldInst="";
                attr =attributes();
                if(attr.hasAttribute("cbName"))
                {
                    tempgv.cbname=attr.value("cbName").toString();
                }
                if(attr.hasAttribute("ldInst"))
                {
                    tempgv.ldInst=attr.value("ldInst").toString();
                }
                tempgv.name="GSE";
                PCOM[pcNum].connap[apNum].gv.append(tempgv);
                read_GSE();
                gvNum++;
            }
            */
            if(name() == "SMV")
            {
                tempgv.cbname="";
                tempgv.ldInst="";
                attr =attributes();
                if(attr.hasAttribute("cbName"))
                {
                    tempgv.cbname=attr.value("cbName").toString();
                }
                if(attr.hasAttribute("ldInst"))
                {
                    tempgv.ldInst=attr.value("ldInst").toString();
                }
                tempgv.name="SMV";
                PCOM[pcNum].connap[apNum].gv.append(tempgv);
                read_SMV();
                gvNum++;
            }
        }
        if(isEndElement())
        {
            if(name() == "ConnectedAP")
                break;
        }
    }
}
void scl_reader::read_GSE()
{
 //   SMVorGOOSE=0;
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "Address")
            {
                read_Address();
            }
        }
        if(isEndElement())
        {
            if(name() == "GSE")
                break;
        }
    }
}
void scl_reader::read_SMV()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "Address")
            {
                read_Address();
            }
        }
        if(isEndElement())
        {
            if(name() == "SMV")
                break;
        }
    }
}
void scl_reader::read_Address()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "P")
            {
                read_P();
            }
        }
        if(isEndElement())
        {
            if(name() == "Address")
            {
                break;
            }
        }
    }
}
void scl_reader::read_P()
{
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("type"))
    {
        if (attr1.value("type").toString()=="MAC-Address")
        {
            PCOM[pcNum].connap[apNum].gv[gvNum].address.MAC=readElementText();
        }
        if (attr1.value("type").toString()=="VLAN-ID")
        {
            PCOM[pcNum].connap[apNum].gv[gvNum].address.VID=readElementText();
        }
        if (attr1.value("type").toString()=="VLAN-PRIORITY")
        {
            PCOM[pcNum].connap[apNum].gv[gvNum].address.VPRIORITY=readElementText();
        }
        if (attr1.value("type").toString()=="APPID")
        {
            PCOM[pcNum].connap[apNum].gv[gvNum].address.APPID=readElementText();
        }
        else
        {
            PCOM[pcNum].connap[apNum].gv[gvNum].address.APPID="FFFF";
        }
    }
}

void scl_reader::read_IED()
{
    tempPIED.name="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempPIED.name=attr1.value("name").toString();
    }
    PIED.append(tempPIED);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "AccessPoint")
            {
                read_AccessPoint();
                acNum++;
                ldNum=0;
            }
        }

        if(isEndElement())
        {
            if(name() == "IED")//AccessPoint
            {
                break;
            }
        }
    }
}
void scl_reader::read_AccessPoint()
{
    tempaccp.name="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempaccp.name=attr1.value("name").toString();
    }
    PIED[piNum].accp.append(tempaccp);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "LDevice")
            {
                read_LDevice();
                ldNum++;
                daNum=0;
                lnNum=0;
                coNum=0;
                ddoNum=0;
            }
        }
        if(isEndElement())
        {
            if(name() == "AccessPoint")//AccessPoint
            {
                break;
            }
        }
    }
}

void scl_reader::read_LDevice()
{
    templd.inst="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("inst"))
    {
        templd.inst=attr1.value("inst").toString();
    }
    PIED[piNum].accp[acNum].ld.append(templd);
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            QString s=name().toString();
            if(s == "LN0")
            {
                read_LN0();
                coNum=0;
                daNum=0;
                ddoNum=0;
            }
            else if(s == "LN")
            {
                read_LNdata();
                lnNum++;
                doNum=0;
            }
        }
        if(isEndElement())
        {
            if(name() == "LDevice")
            {
                break;
            }
        }
    }
}
void scl_reader::read_LN0()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "DataSet")
            {
                read_DataSet();
            }
            if(name() == "DOI")
            {
                read_DDOI();
            }
            else if(name() == "GSEControl")
            {
                read_GSEControl();
                coNum++;
            }
            else if (name() == "SampledValueControl")
            {
                read_SampledValueControl();
                coNum++;
            }
        }
        if(isEndElement())
        {
            if(name() == "LN0")//AccessPoint
            {
                break;
            }
        }
    }
}

void scl_reader::read_DataSet()
{
    tempdataset.name="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempdataset.name=attr1.value("name").toString();
        PIED[piNum].accp[acNum].ld[ldNum].dataset.append(tempdataset);
        read_FCDA();
        fcNum=0;
        daNum++;
    }
}
void scl_reader::read_DDOI()
{
    tempddoi.dai="";
    tempddoi.name="";
    tempddoi.desc="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempddoi.name=attr1.value("name").toString();
        if(attr1.hasAttribute("desc"))
            tempddoi.desc=attr1.value("desc").toString();
        while(!atEnd())
        {
            readNext();
            if(isStartElement())
            {
                if(name() == "DAI")
                {
                    attr1 =attributes();
                    if(attr1.hasAttribute("name"))
                    {
                        QString s=attr1.value("name").toString();
                        if (s=="dU")
                        {
                            while(!atEnd())
                            {
                                readNext();
                                if(isStartElement())
                                {
                                    if(name() == "Val")
                                    {
                                        tempddoi.dai=readElementText();
                                    }
                                }
                                if(isEndElement())
                                {
                                     if (name() == "DAI")
                                     {
                                         break;
                                     }
                                }
                            }
                        }
                    }
                }
            }
            if(isEndElement())
            {
                 if (name() == "DOI")
                 {
                     break;
                 }
            }
        }
    }
    PIED[piNum].accp[acNum].ld[ldNum].doi.append(tempddoi);
    ddoNum++;
}

void scl_reader::read_FCDA()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "FCDA")
            {
                tempfcda.lnClass="";
                tempfcda.lnInst="";
                tempfcda.doName="";
                tempfcda.daName="";
                tempfcda.prefix="";
                QXmlStreamAttributes attr1 =attributes();
                if(attr1.hasAttribute("lnClass"))
                {
                    tempfcda.lnClass=attr1.value("lnClass").toString();
                }
                if(attr1.hasAttribute("lnInst"))
                {
                    tempfcda.lnInst=attr1.value("lnInst").toString();
                //    PIED[piNum].accp[acNum].dataset[daNum].fcda[fcNum].lnInst=attr1.value("lnInst").toString();
                }
                if(attr1.hasAttribute("doName"))
                {
                    tempfcda.doName=attr1.value("doName").toString();
                //    PIED[piNum].accp[acNum].dataset[daNum].fcda[fcNum].doName=attr1.value("doName").toString();
                }
                if(attr1.hasAttribute("daName"))
                {
                    tempfcda.daName=attr1.value("daName").toString();
                //    PIED[piNum].accp[acNum].dataset[daNum].fcda[fcNum].daName=attr1.value("daName").toString();
                }
                if(attr1.hasAttribute("prefix"))
                {
                    tempfcda.prefix=attr1.value("prefix").toString();
               //     PIED[piNum].accp[acNum].dataset[daNum].fcda[fcNum].prefix=attr1.value("prefix").toString();
                }
            //    qDebug()<<piNum<<" "<<acNum<<" "<<ldNum<<" "<<daNum<<" "<<fcNum;
            //    qDebug()<<PIED[piNum].accp[acNum].ld[ldNum].dataset.length();
                PIED[piNum].accp[acNum].ld[ldNum].dataset[daNum].fcda.append(tempfcda);
                fcNum++;
                PIED[piNum].accp[acNum].ld[ldNum].dataset[daNum].num=fcNum;
              //  qDebug()<<fcNum;
              //  qDebug()<<piNum<<" "<<acNum<<" "<<ldNum<<" "<<daNum<<" "<<fcNum;
           }
       }
       if(isEndElement())
       {
            if (name() == "DataSet")
            {
                break;
            }
       }
   }
}
void scl_reader::read_GSEControl()
{
    tempcontrol.name="";
    tempcontrol.DatSet="";
    tempcontrol.appID="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempcontrol.name=attr1.value("name").toString();
     //   PIED[piNum].accp[acNum].ld[ldNum].control[coNum].name=attr1.value("name").toString();
     //   gsecontrol[gseNum].name=attr1.value("name").toString();
    }
    if(attr1.hasAttribute("datSet"))
    {
        tempcontrol.DatSet=attr1.value("datSet").toString();
     //   gsecontrol[gseNum].datset=attr1.value("datSet").toString();
    }
    if(attr1.hasAttribute("appID"))
    {
        tempcontrol.appID=attr1.value("appID").toString();
    }
    PIED[piNum].accp[acNum].ld[ldNum].control.append(tempcontrol);
  //  qDebug()<<tempcontrol.name;
    coNum++;
}
void scl_reader::read_SampledValueControl()
{
    tempcontrol.name="";
    tempcontrol.DatSet="";
    tempcontrol.appID="";
    tempcontrol.smpRate="";
    tempcontrol.asdu="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("name"))
    {
        tempcontrol.name=attr1.value("name").toString();
     //   PIED[piNum].accp[acNum].ld[ldNum].control[coNum].name=attr1.value("name").toString();
    //    smvcontrol[smvNum].name=attr1.value("name").toString();
    }
    if(attr1.hasAttribute("datSet"))
    {
        tempcontrol.DatSet=attr1.value("datSet").toString();
    //    smvcontrol[smvNum].datset=attr1.value("datSet").toString();
    }
    if(attr1.hasAttribute("smvID"))
    {
        QString s=attr1.value("smvID").toString();
    //    qDebug()<<s <<" "<<piNum<<" "<<acNum<<" "<<coNum;
        tempcontrol.appID=s;
     //   smvcontrol[smvNum].svID=attr1.value("smvID").toString();
    }
    if(attr1.hasAttribute("smpRate"))
    {
        tempcontrol.smpRate=attr1.value("smpRate").toString();
  //      smvcontrol[smvNum].smpRate=attr1.value("smpRate").toString();
    }
    if(attr1.hasAttribute("nofASDU"))
    {
        tempcontrol.asdu=attr1.value("nofASDU").toString();
  //      smvcontrol[smvNum].smpRate=attr1.value("smpRate").toString();
    }
 //   smvNum++;
    PIED[piNum].accp[acNum].ld[ldNum].control.append(tempcontrol);
    coNum++;
}
/*
void scl_reader::read_LN()
{
  //  tdNum1=0;

    while(!atEnd())
    {
        readNext();
        QString s=name().toString();
        qDebug()<<s;
        if(isStartElement())
        {
            if(name() == "LN")
            {
                read_LNdata();
            }
        }
        if(isEndElement())
        {
            if(name() == "LN")
            {
                break;
            }
        }
    }
}
*/
void scl_reader::read_LNdata()
{
    templn.lnClass="";
    templn.lnSt="";
    templn.desc="";
    templn.prefix="";
    QXmlStreamAttributes attr1 =attributes();
    if(attr1.hasAttribute("lnClass"))
    {
        templn.lnClass=attr1.value("lnClass").toString();
     //   PIED[piNum].accp[acNum].ln[lnNum].lnClass=attr1.value("lnClass").toString();
    //    PIED[piNum].ln[tdNum1].lnClass=attr1.value("lnClass").toString();
    }
    if(attr1.hasAttribute("inst"))
    {
        templn.lnSt=attr1.value("inst").toString();
    //    PIED[piNum].accp[acNum].ln[lnNum].lnSt=attr1.value("inst").toString();
    //    PIED[piNum].ln[tdNum1].lnSt=attr1.value("inst").toString();
    }
    if(attr1.hasAttribute("desc"))
    {
        templn.desc=attr1.value("desc").toString();
      //  PIED[piNum].accp[acNum].ln[lnNum].desc=attr1.value("desc").toString();
    //    PIED[piNum].ln[tdNum1].desc=attr1.value("desc").toString();
    }
    if(attr1.hasAttribute("prefix"))
    {
        templn.prefix=attr1.value("prefix").toString();
     //   PIED[piNum].accp[acNum].ln[lnNum].prefix=attr1.value("prefix").toString();
    //    PIED[piNum].ln[tdNum1].prefix=attr1.value("prefix").toString();
    }
  //  PIED[piNum].accp[acNum].ln.append(ln);
    PIED[piNum].accp[acNum].ld[ldNum].ln.append(templn);
    read_DOI();
  //  tdNum1++;

 //   lnNum++;
}
void scl_reader::read_DOI()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "DOI")
            {
              //  struct Doi doi;
                tempdoi.name="";
                tempdoi.desc="";
                tempdoi.DAI="";
                QXmlStreamAttributes attr1 =attributes();
                if(attr1.hasAttribute("name"))
                {
                    tempdoi.name=attr1.value("name").toString();

                    if(attr1.hasAttribute("desc"))
                    {
                        tempdoi.desc=attr1.value("desc").toString();
                    }
                    PIED[piNum].accp[acNum].ld[ldNum].ln[lnNum].doi.append(tempdoi);
                    read_DAI();
                    doNum++;
                }
            }
        }
        if(isEndElement())
        {
            if(name() == "LN")//LN
            {
                break;
            }
        }
    }
}
void scl_reader::read_DAI()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "DAI")
            {
                QXmlStreamAttributes attr1 =attributes();
                if(attr1.hasAttribute("name"))
                {
                    QString s=attr1.value("name").toString();
                    if (s=="dU")
                        read_Val();
                }
            }
        }
        if(isEndElement())
        {
            if(name() == "DOI")
            {
                break;
            }
        }
    }
}
void scl_reader::read_Val()
{
    while(!atEnd())
    {
        readNext();
        if(isStartElement())
        {
            if(name() == "Val")
            {
                tempdoi.DAI=readElementText();
                PIED[piNum].accp[acNum].ld[ldNum].ln[lnNum].doi.append(tempdoi);
            //    PIED[piNum].accp[acNum].ld[ldNum].ln.append(templn);
             //   qDebug()<<piNum<<" "<<acNum<<" "<<ldNum<<":"<<doNum;
              //  qDebug()<<sizeof(PIED);
             //   qDebug()<<piNum<<" "<<acNum<<" "<<ldNum;
            //    PIED[piNum].accp[acNum].ln[lnNum].doi[doNum].DAI=readElementText();
          //      QString s=readElementText();
          //      PIED[piNum].ln[tdNum1].doi[tdNum2].DAI=s;
            }
        }
        if(isEndElement())
        {
            if(name() == "DAI")
            {
                break;
            }
        }
    }
}

void scl_reader::connectData()
{
    int ipc=PCOM.length();
    for(int i=0;i<ipc;i++)
    {
        int jpc=PCOM[i].connap.length();
        for(int j=0;j<jpc;j++)
        {
            int mpc=PCOM[i].connap[j].gv.length();
            for(int m=0;m<mpc;m++)
            {
                if (!PCOM[i].connap[j].gv[m].cbname.isEmpty())
                {
                    int ipc1=PIED.length();
                    for(int i1=0;i1<ipc1;i1++)
                    {
                        if (PIED[i1].name==PCOM[i].connap[j].iedName)
                        {
                            int jpc1=PIED[i1].accp.length();
                            for(int j1=0;j1<jpc1;j1++)
                            {
                                int lpc1=PIED[i1].accp[j1].ld.length();
                                for(int l1=0;l1<lpc1;l1++)
                                {
                                    if (PIED[i1].accp[j1].ld[l1].inst==PCOM[i].connap[j].gv[m].ldInst)
                                    {
                                        int npc1=PIED[i1].accp[j1].ld[l1].control.length();
                                        for(int n1=0;n1<npc1;n1++)
                                        {
                                            if (PIED[i1].accp[j1].ld[l1].control[n1].name==PCOM[i].connap[j].gv[m].cbname)
                                            {
                                                PCOM[i].connap[j].gv[m].address.sID=PIED[i1].accp[j1].ld[l1].control[n1].appID;
                                                int mpc1=PIED[i1].accp[j1].ld[l1].dataset.length();
                                                for(int m1=0;m1<mpc1;m1++)
                                                {
                                                    if(PIED[i1].accp[j1].ld[l1].control[n1].DatSet==PIED[i1].accp[j1].ld[l1].dataset[m1].name)
                                                    {
                                                        PCOM[i].connap[j].gv[m].address.num=QString::number(PIED[i1].accp[j1].ld[l1].dataset[m1].num);

                                                      //  sWz[iWz].a=i1;
                                                      //  sWz[iWz].b=j1;
                                                       // sWz[iWz].c=m1;
                                                      //  sWz[iWz].d=l1;
                                                      //  iWz++;
                                                        clearTemp();
                                                        tempSub.add.APPID=PCOM[i].connap[j].gv[m].address.APPID;
                                                        tempSub.add.MAC=PCOM[i].connap[j].gv[m].address.MAC;
                                                        tempSub.add.VID=PCOM[i].connap[j].gv[m].address.VID;
                                                        tempSub.add.VPRIORITY=PCOM[i].connap[j].gv[m].address.VPRIORITY;
                                                        tempSub.iedName=PCOM[i].connap[j].iedName;
                                                        tempSub.name=PCOM[i].connap[j].gv[m].name;
                                                        tempSub.num=PIED[i1].accp[j1].ld[l1].dataset[m1].num;
                                                        tempSub.SID=PIED[i1].accp[j1].ld[l1].control[n1].appID;
                                                        tempSub.add.smpRate=PIED[i1].accp[j1].ld[l1].control[n1].smpRate;
                                                        tempSub.add.asdu=PIED[i1].accp[j1].ld[l1].control[n1].asdu;
                                                        PSUB.append(tempSub);

                                                        int tm=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.length();
                                                        int tn=PIED[i1].accp[j1].ld[l1].ln.length();
                                                        for(int t1=0;t1<tm;t1++)
                                                        {
                                                            for(int t2=0;t2<tn;t2++)
                                                            {
                                                                if((PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).lnClass==PIED[i1].accp[j1].ld[l1].ln.at(t2).lnClass)
                                                                    &&(PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).lnInst==PIED[i1].accp[j1].ld[l1].ln.at(t2).lnSt))
                                                                {
                                                                    tempfc.lnClass=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).lnClass;
                                                                    int to=PIED[i1].accp[j1].ld[l1].ln[t2].doi.length();
                                                                  //  if (!reader.PCOM[i].connap[j].gv[m].name.isEmpty())
                                                                  //  qDebug()<<reader.PCOM[i].connap[j].gv[m].name;
                                                                    if (PCOM[i].connap[j].gv[m].name=="SMV")
                                                                    {
                                                                        if(PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).prefix==PIED[i1].accp[j1].ld[l1].ln.at(t2).prefix)
                                                                        {
                                                                        PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].desc=PIED[i1].accp[j1].ld[l1].ln[t2].desc;
                                                                        tempfc.desc=PIED[i1].accp[j1].ld[l1].ln[t2].desc;

                                                                        for(int d1=0;d1<to;d1++)
                                                                        {
                                                                            if(PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].doName==PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].name)
                                                                            {
                                                                                PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].dOI=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].desc;
                                                                                PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].dAI=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].DAI;
                                                                                tempfc.doi=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].desc;
                                                                                tempfc.dai=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].DAI;
                                                                                tempfc.daName=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].daName;
                                                                                tempfc.doName=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].doName;

                                                                            //    PSUB[PSUB.length()-1].fc[tm].dai=tempfc.dai;
                                                                            //    PSUB[PSUB.length()-1].fc[tm].doi=tempfc.doi;
                                                                             //   PSUB[PSUB.length()-1].fc[tm].daName=tempfc.daName;
                                                                             //   PSUB[PSUB.length()-1].fc[tm].doName=tempfc.doName;
                                                                         //       PSUB[PSUB.length()-1].fc.append(tempfc);
                                                                           //     qDebug()<<" "<<tempfc.doi<<tempfc.dai<<" "<<tempfc.desc<<" "<<PSUB[PSUB.length()-1].fc.length();

                                                                            }
                                                                        }
                                                                        }
                                                                    }
                                                                    else if (PCOM[i].connap[j].gv[m].name=="GSE")
                                                                    {

                                                                       //     qDebug()<<reader.PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).lnClass;

                                                                        if(PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).prefix==PIED[i1].accp[j1].ld[l1].ln.at(t2).prefix)
                                                                        {
                                                                      //      if (reader.PIED[i1].name=="P220FY1B")
                                                                      //          qDebug()<<i1<<" "<<j1<<" "<<l1<<" "<<m1<<" "<<t1<<" "<<reader.PIED[i1].accp[j1].ld[l1].ln.at(t2).desc;
                                                                       //     qDebug()<<reader.PIED[i1].accp[j1].ld[l1].dataset[n1].fcda.at(t1).prefix<<" "<<reader.PIED[i1].name<<" "<<reader.PIED[i1].accp[j1].ld[l1].dataset[n1].fcda.at(t1).lnClass<<" "<<reader.PIED[i1].accp[j1].ld[l1].ln.at(t2).desc;

                                                                            PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].desc=PIED[i1].accp[j1].ld[l1].ln.at(t2).desc;
                                                                            tempfc.desc=PIED[i1].accp[j1].ld[l1].ln[t2].desc;
                                                                          //  if (reader.PIED[i1].name=="P220FY1B")
                                                                          //      qDebug()<<reader.PIED[i1].accp[j1].ld[l1].ln.at(t2).desc;

                                                                            for(int d1=0;d1<to;d1++)
                                                                            {
                                                                                if(PIED[i1].accp[j1].ld[l1].dataset[m1].fcda.at(t1).doName==PIED[i1].accp[j1].ld[l1].ln.at(t2).doi[d1].name)
                                                                                {
                                                                                    PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].dOI=PIED[i1].accp[j1].ld[l1].ln.at(t2).doi[d1].desc;
                                                                                    PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].dAI=PIED[i1].accp[j1].ld[l1].ln.at(t2).doi[d1].DAI;
                                                                                    tempfc.doi=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].desc;
                                                                                    tempfc.dai=PIED[i1].accp[j1].ld[l1].ln[t2].doi[d1].DAI;
                                                                                    tempfc.daName=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].daName;
                                                                                    tempfc.doName=PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].doName;
                                                                             //       PSUB[PSUB.length()-1].fc.append(tempfc);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if (tempfc.doi=="")
                                                            {
                                                                int tp=PIED[i1].accp[j1].ld[l1].doi.length();
                                                                for(int t3=0;t3<tp;t3++)
                                                                {
                                                                    if (PIED[i1].accp[j1].ld[l1].doi[t3].name==PIED[i1].accp[j1].ld[l1].dataset[m1].fcda[t1].doName)
                                                                    {
                                                                        tempfc.doi=PIED[i1].accp[j1].ld[l1].doi[t3].desc;
                                                                        tempfc.dai=PIED[i1].accp[j1].ld[l1].doi[t3].dai;
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                            PSUB[PSUB.length()-1].fc.append(tempfc);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                //    QStandardItem* item0=new QStandardItem();

                }
            }
        }
    }
}
void scl_reader::clearTemp()
{
    tempSub.add.APPID="";
    tempSub.add.MAC="";
    tempSub.add.VID="";
    tempSub.add.VPRIORITY="";
    tempSub.add.smpRate="";
    tempSub.add.asdu="";
    tempfc.dai="";
    tempfc.daName="";
    tempfc.desc="";
    tempfc.doi="";
    tempfc.doName="";
    tempfc.lnClass="";
    tempSub.name="";
    tempSub.num=0;
    tempSub.SID="";
    tempSub.type="";
}
